<?php  session_start();
include('functions.php');
if ($_SESSION["pass"] != check($_SESSION["user"])) {
  secure();
exit;
} elseif(!isset($_SESSION["pass"])) {
  secure();
exit;
}
function ApplyFunc($allow, $dir, $file) {
$fullpath = "$dir$file";
global $show, $del, $edit, $rename, $copy, $move;
$links = "";
list($showable, $deleteable, $editable, $renameable, $copyable, $moveable) = $allow;
if ($show == 'true' || $_SESSION['power'] == 'Administrator' && $showable == 'true') {
$links .= '<br /><a href="showfile.php?dir='.$fullpath.'" target="viewer">Show File</a>';
} if ($del == 'true' || $_SESSION['power'] == 'Administrator' && $deleteable == 'true') {
$links .= '<br /><a href="trashit.php?dir='.$dir.'&file='.$file.'">Delete File</a>';
} if ($edit == 'true' || $_SESSION['power'] == 'Administrator' && $editable == 'true') {
$links .= '<br /><a href="edit.php?dir='.$fullpath.'" target=_blank>Edit File</a>';
}
 //AN IF WOULD GO HERE REMOVEABLE FUNCTION
$links .= '<br /><a href="perm.php?dir='.$dir.'&file='.$file.'">Change Permision</a>';
//}
if ($rename == 'true' || $_SESSION['power'] == 'Administrator' && $renameable == 'true') {
$links .= '<br /><a href="rename.php?dir='.$dir.'&file='.$file.'" target=infofr>Rename File</a>';
} if ($copy == 'true' || $_SESSION['power'] == 'Administrator' && $copyable == 'true') {
$links .= '<br /><a href="list.php?copy=true&old='.$dir.'&file='.$file.'" target=filemain>Copy File</a>';
} if ($move == 'true' || $_SESSION['power'] == 'Administrator' && $moveable == 'true') {
$links .= '<br /><a href="list.php?move=true&old='.$dir.'&file='.$file.'" target=filemain>Move File</a>';
}
return $links;
} // end function
$dir = $_GET['dir']; // les know about our folder location
if(!isset($_GET['zip']) && !isset($_GET['wr']) && !isset($_GET['file'])) {
$folder = true; // make sure we know its a folder
} elseif(!isset($_GET['zip']) && !isset($_GET['wr'])) {
$file = $_GET['file']; // get just the file name
} elseif(isset($_GET['zip'])) {
$file = "".$_GET['name'].".zip";
}
if(isset($file)) {
$fullpath = "$dir$file"; // lets put the last two veriables together
$doc_root = "" .$_SERVER['DOCUMENT_ROOT']. "/";
$root_lng = strlen($doc_root);
$test = strrchr($fullpath,'.');
if(!is_dir($fullpath)) {
if(strlen($fullpath) >= $root_lng) {
$folders = substr($fullpath, $root_lng);
$link_txt ="http://" .$_SERVER["SERVER_NAME"]. "/" .$folders. "";
$link = preg_replace('/\s+/', '%20', $link_txt);
}
}
if($debug != 'true') {
$config_test = realpath("./config.php");
$oPanel_dir = dirname("$config_test");
$real_dir_full = realpath("$fullpath");
if ($real_dir_full == $config_test) {
$content = "<br /><font color=\"red\">You can't edit the config for oPanel.";
} elseif($real_dir == $oPanel_dir) {
$content = "<br /><font color=\"red\">You can't edit oPanel Files!";
}
}
} // isset($file)
if (isset($_GET['zip']) && $_GET['zip'] =="true") {
 $x = new xml();
 $source = file_get_contents('includes/filetypes.xml');
 $x->fetch($source);
$tpe = strrchr($file,'.');
$type = strtoupper(str_replace('.','',$tpe));
$ext = $x->data->FILETYPES[0]->EXTENTIONS[0];
$current = $ext->$type;
 $imgsrc = $current[0]->_attr->IMG;
 $filedesc = "<br />File type: ".$current[0]->_attr->DISCRIP;
$content = "<br /><font color=\"red\">oPanel does not support the use of zip files at this time.</font>";
$allowFunc = array('false','true', 'false', 'false', 'true', 'true');
$content .= ApplyFunc($allowFunc, $dir, $file);
if(isset($link)) { 
$content .= '<br /><br />File Url: <a href="'.$link.'" target="_blank"><b>'.$link_txt.'</b></a>';
}
} elseif(isset($folder) && $folder == true) {
$imgsrc = "images/i-directory.gif";
$filedesc = '';
$file = basename($dir);
if ($del == true || $_SESSION['power'] == 'Administrator') {
$content = '<br /><a href="trashit.php?dir='.$dir.'">Delete This Folder And All Files Under It</a>';
} if ($rename == true || $_SESSION['power'] == 'Administrator') {
$content .= '<br /><a href="rename.php?dir='.$dir.'" target=infofr>Rename This Folder</a>';
}//if() would go here
$content .= '<br /><a href="perm.php?dir='.$dir.'">Change Permision</a>';
//}
if ($move == true || $_SESSION['power'] == 'Administrator') {
$content .= '<br /><a href="list.php?move=true&old='.$dir.'" target=filemain>Move This Folder</a>';
} if ($copy == true || $_SESSION['power'] == 'Administrator') {
$content .= '<br /><a href="list.php?copy=true&old='.$dir.'" target=filemain>Copy This Folder</a>';
}
} else {
 $x = new xml();
 $source = file_get_contents('includes/filetypes.xml');
 $x->fetch($source);
$tpe = strrchr($file,'.');
if(isset($tpe) && $tpe == "") { $imgsrc = 'images/i-regular.gif'; $filedesc = '<br />File type: Unkown file type'; } else {
$type = strtoupper(str_replace('.','',$tpe));
$ext = $x->data->FILETYPES[0]->EXTENTIONS[0];
if(isset($ext->$type) && $current = $ext->$type) { $imgsrc = $current[0]->_attr->IMG; $filedesc = "<br />File type: ".$current[0]->_attr->DISCRIP;
} else { $imgsrc = 'images/i-regular.gif'; $filedesc = '<br />File type: Unkown file type';  } }
if(!is_writable($fullpath)) {
$content = "<font color=\"red\"><b>WARNING:</b><br />
\nThe file you have selected is not writeable<br />
This means you can't edit it<br />
Please tell your oPanel Administrator.</font>";
$allowFunc = array('true','true', 'false', 'false', 'true', 'true');
$content .= ApplyFunc($allowFunc, $dir, $file);
if(isset($link)) { $content .= '<br /><br />File Url: <a href="'.$link.'" target="_blank"><b>'.$link_txt.'</b></a>'; }
} elseif(isset($type) && $type == 'OPLF') {
$allowFunc = array('false','false', 'false', 'false', 'false', 'false');
$content = "<font color=\"red\"><b>WARNING:</b><br />
\n<span style=\"text-align: justify;\">This file contains your oPanel License code
\n<p>Editing of this file is strictly prohibited.<br />
\nIf you wish to edit your license you may via the <a href=\"admin.php\" target=\"_blank\">oPanel
Administration area</a>.</p></span></font>";
} elseif(!isset($_GET['zip'])) {
$ed = $x->data->FILETYPES[0]->NONEDITEXTENTIONS[0];
if(isset($type) && isset($ed->$type)) { $allowFunc = array('true','true', 'false', 'true', 'true', 'true'); $edit = false; } else {
$allowFunc = array('true','true', 'true', 'true', 'true', 'true'); }
if(isset($content)) {
$content .= ApplyFunc($allowFunc, $dir, $file);
if(isset($link)) { 
$content .= '<br /><br />File Url: <a href="'.$link.'" target="_blank"><b>'.$link_txt.'</b></a>';
}
} else {

$content = ApplyFunc($allowFunc, $dir, $file);
if(isset($link)) { 
$content .= '<br /><br />File Url: <a href="'.$link.'" target="_blank"><b>'.$link_txt.'</b></a>';
}
}
}
}
$html = <<<HTM
<html>
<head>
<title>oPanel V$ver</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet"href="style.css">
</head>
<body>
<center><img src="images/logo.png"></center>
<font class=med><img src="$imgsrc">
<b><font size=+1>$file</font></b>
$filedesc
<br />
$content
</font> 
</body>
</html>
HTM;
echo $html;
?>